package cn.com.dstz.admin.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;

import cn.com.dstz.base.action.BaseAction;

public class GonggaoAct extends BaseAction{

	/**
	 * 显示公告
	 * @author 黄阳晨
	 */
	public void list(){
		String sql = "SELECT g.id , g.content,g.sendtime from dstzgg g WHERE g.aid=:aid order by g.sendtime desc";
		String aid = getRequest().getParameter("aid");
		Map<String,Object> valueMap = new HashMap<String,Object>();
		valueMap.put("aid", aid);
		Map<String,Object> resultMap = this.paginationBySQL(sql, "", valueMap, "");
		List< Map< String, Object >> resultList = ( List< Map< String, Object >>) resultMap.get( "rows" );
		for( Map< String, Object > result : resultList ){
			String content = ( String ) result.get( "content" );
			content = Jsoup.clean( content, Whitelist.none( ) );
			int len = content.length( );
			
			if( len > 60 ){
				content = content.substring( 0, 60 ) + "...【阅读全文】";
			}
			result.put( "content", content );
		}
		this.responseToJsonObject( resultMap  );
		return ;
	}
	
	public String toView(){
		String sql = "select g.* ,a.username as username from dstzgg g,dstzadmin a  where g.adminid=a.id and g.id =:id";
		Map<String,Object> valueMap = new HashMap<String,Object>();
		valueMap.put("id", getRequest().getParameter("id"));
		Map<String,Object> data = baseService.queryForMap(sql, valueMap);
		getRequest().setAttribute("data", data);
		return "view";
	}
	private static final long serialVersionUID = 1L;
	
}
